<template>
    <el-dialog :title="title" class="addPedestal" width="480px" :visible.sync="isDial">
    <el-form :model="form">
        <el-form-item label="栋座名称" :label-width="formLabelWidth">
            <el-input size="mini" v-model="form.prefix" autocomplete="off" placeholder="前缀" style="width:100px;margin-right:5px"></el-input>
          <el-input size="mini" v-model="form.name" autocomplete="off" :maxlength="10" style="width:150px;margin-right:5px"></el-input>
          <el-select size="mini" v-model="form.type" placeholder="幢" style="width:80px">
            <el-option label="幢" value="幢"></el-option>
            <el-option label="座" value="座"></el-option>
            <el-option label="栋" value="栋"></el-option>
            <el-option label="号" value="号"></el-option>
          </el-select>
        </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" size="mini" @click="savePedestal">保 存</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { request } from "../../../assets/request.js";
export default {
    data(){
        return{
            form:{
                prefix:'前缀',
                name:"",
                type:''
            },
            id:'',
            formLabelWidth:'80px',
            isDial:false,
            title:"修改栋座"
        }
    },
    created(){
        let that = this;
        this.$root.$on("editPedestal", (type,data) => {
            console.log(data)
            let form=that.form
            form.type=data.unit;
            that.id=data.id
            form.name=data.name
            let prefix=data.prefix
            if(data.prefix==' '){ //去除空格
                form.prefix=''
            }else{
                form.prefix=data.prefix
            }
            that.form=form
            that.isDial = true;
        });
    },
    methods:{
        savePedestal(){
            let that=this
            let met='PUT'
            let params={
                id:that.id,
                name:that.form.name,
                unit:that.form.type,
                prefix:that.form.prefix
            }
            let url="houses/unit"
            request.ajaxPost({
            url,
            that,
            type:met,
            params,
            fn(res) {
                console.log(res);
                that.isDial = false;
                that.$root.$emit("pedestalList");
            }
            });
        }
    }
}
</script>
<style lang="less" scoped>

</style>
